package com.hzlx.operations.controller;

import java.util.List;
import java.io.IOException;

import com.hzlx.ResultDto;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.operations.domain.Operations;
import com.hzlx.operations.service.IOperationsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工序Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/base")
public class OperationsController extends BaseController
{
    @Autowired
    private IOperationsService operationsService;
    //两表联查 查询工艺路线和参数，用于返回前端
    @GetMapping(value = "/operationsWithParam/{operationId}")
    public ResultDto<Operations> getOpWithParam(@PathVariable("operationId") Long operationId)
    {
        return ResultDto.<Operations>builder().code(200).data(operationsService.selectOperationsWithParams(operationId)).build();
    }

    /**
     * 查询工序列表
     */
    @RequiresPermissions("base-data-service:operations:list")
    @GetMapping("/operations/list")
    public TableDataInfo list(Operations operations)
    {
        startPage();
        List<Operations> list = operationsService.selectOperationsList(operations);
        return getDataTable(list);
    }

    /**
     * 导出工序列表
     */
    @RequiresPermissions("base-data-service:operations:export")
    @Log(title = "工序", businessType = BusinessType.EXPORT)
    @PostMapping("/operations/export")
    public void export(HttpServletResponse response, Operations operations)
    {
        List<Operations> list = operationsService.selectOperationsList(operations);
        ExcelUtil<Operations> util = new ExcelUtil<Operations>(Operations.class);
        util.exportExcel(response, list, "工序数据");
    }

    /**
     * 获取工序详细信息
     */
    @RequiresPermissions("base-data-service:operations:query")
    @GetMapping(value = "/operations/{operationId}")
    public AjaxResult getInfo(@PathVariable("operationId") Long operationId)
    {
        return success(operationsService.selectOperationsByOperationId(operationId));
    }

    /**
     * 新增工序
     */
    @RequiresPermissions("base-data-service:operations:add")
    @Log(title = "工序", businessType = BusinessType.INSERT)
    @PostMapping("/operations")
    public AjaxResult add(@RequestBody Operations operations)
    {
        return toAjax(operationsService.insertOperations(operations));
    }

    /**
     * 修改工序
     */
    @RequiresPermissions("base-data-service:operations:edit")
    @Log(title = "工序", businessType = BusinessType.UPDATE)
    @PutMapping("/operations")
    public AjaxResult edit(@RequestBody Operations operations)
    {
        return toAjax(operationsService.updateOperations(operations));
    }

    /**
     * 删除工序
     */
    @RequiresPermissions("base-data-service:operations:remove")
    @Log(title = "工序", businessType = BusinessType.DELETE)
	@DeleteMapping("/operations/{operationIds}")
    public AjaxResult remove(@PathVariable Long[] operationIds)
    {
        return toAjax(operationsService.deleteOperationsByOperationIds(operationIds));
    }
}
